#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 2e5 + 10, INF = 0x3f3f3f3f3f3f3f3f;

ll n;
ll a[N], s[N];

ll getsum(ll M, ll mid) { return (mid - 1) * M - s[mid - 1] + s[n] - s[mid] - (n - mid) * M; }

ll f(ll x)
{
    ll mid = (n + 1) / 2;
    //我的推导是如果是奇数长度的话，那么当删除的位置在原来中位数位置或者或者右边，则删除后的新中位数是mid - 1位置上
    if (n % 2 == 1 && x >= mid) mid--;
    //如果是偶数长度的话，那么当删除的位置在原来中位数位置或者或者左边，则删除后的新中位数是mid + 1位置上
    if (n % 2 == 0 && x <= mid) mid++;
    return getsum(a[mid], mid) - abs(a[mid] - a[x]);
}

void solve()
{
    cin >> n;
    for (ll i = 1;i <= n;i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    for (ll i = 1;i <= n;i++) s[i] = s[i - 1] + a[i];
    ll ans = INF;
    for (ll i = 1;i <= n;i++) {
        ans = min(ans, f(i));
    }
    cout << ans << '\n';
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    cin >> T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}